import axios from '@/utils/request';
import qs from 'qs';
const baseOriginURL = process.env.VUE_APP_BASE_ORIGIN + '/iot_user';

// 获取用户信息
const getUserByToken = () => {
  return axios.get(baseOriginURL + '/user/getUserByToken');
};

// 修改密码
const setPassword = data => {
  return axios.request({
    method: 'PUT',
    url: baseOriginURL + '/user/setPassword',
    data: qs.stringify(data),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  });
};

// 获取邮件验证码
const getEmailCode = params => {
  return axios.get(baseOriginURL + '/user/getEmailCode', {
    params
  });
};

// 设置电子邮件
const setEmail = data => {
  return axios.request({
    method: 'PUT',
    url: baseOriginURL + '/user/setEmail',
    data: qs.stringify(data),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  });
};

// 修改手机号
const editMobile = data => {
  return axios.request({
    method: 'PUT',
    url: baseOriginURL + '/user/editMobile',
    data: qs.stringify(data),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  });
};

export { getUserByToken, setPassword, getEmailCode, setEmail, editMobile };
